package com.hyper_yang.javase.learnException.mayOccur;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class ExceptionTest {

    @DisplayName("算数运算异常: /0")
    @Test
    public void test01(){
        // java.lang.ArithmeticException: / by zero
        int a = 10 / 0;
        System.out.println(a);
    }

    @DisplayName("数组越界异常: ")
    @Test
    public void test02(){
        // java.lang.ArrayIndexOutOfBoundsException
        int[] a = new int[3];
        System.out.println(a[3]);
    }

    @DisplayName("空指针异常: ")
    @Test
    public void test03(){
        // java.lang.NullPointerException
        Object obj = null;
        obj.hashCode();
    }

    @DisplayName("类型转换异常: ")
    @Test
    public void test04(){
        // java.lang.ClassCastException
        Animal animal = new Dog();
        Cat cat = (Cat) animal;
    }
}

class Animal {}
class Dog extends Animal {}
class Cat extends Animal {}